refactor(versionmap): Version-only keys, Mapping API, and iter_pairs#997
refactor(versionmap): Version-only keys, Mapping API, and iter_pairs#997vshawrh wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThe PR refactors VersionMap to implement collections.abc.Mapping[Version, Any], adding iter and len and changing versions() to return an iterator. Initialization, add, and getitem now require packaging.version.Version keys and raise TypeError for non-Version keys; internal string-to-Version conversion was removed. VersionMap iteration yields versions in descending order. Resolver.find_candidates() was updated to iterate over the VersionMap via items() (producing (version, url) pairs) instead of indexing per-version. Tests were updated to use Version keys and to assert the new type and mapping behaviors. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| """ | ||
| for version in self.versions(): | ||
| yield version, self._content[version] | ||
|
|
There was a problem hiding this comment.
Is it necessary to introduce a new function? The items() method from Mapping ABC already returns key/value pairs.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/fromager/versionmap.py (1)
11-15: ⚡ Quick winAdd a
versionchangednote for the breaking key-type contract.This docstring describes a user-facing breaking change but doesn’t include a Sphinx
.. versionchanged::directive.Suggested doc update
class VersionMap(Mapping[Version, typing.Any]): """Read-only mapping protocol over versions with helpers for resolution. + .. versionchanged:: 0.0.0 + Keys must be :class:`packaging.version.Version` instances. String key + coercion/parsing was removed; callers must parse before use. + Keys must be :class:`packaging.version.Version` instances; callers are responsible for parsing strings. Mutate the map via :meth:`add`. """As per coding guidelines: "
**/*.{rst,py}: Use Sphinxversionadded,versionremoved,versionchangeddirectives for user-facing changes".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fromager/versionmap.py` around lines 11 - 15, Update the module docstring in src/fromager/versionmap.py to include a Sphinx ".. versionchanged::" directive documenting the breaking key-type contract: state that keys are now required to be packaging.version.Version instances (callers must parse strings) and reference the mutation method add; include the project version (or placeholder) after ".. versionchanged::" and a short note describing the change and its impact on callers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/fromager/versionmap.py`:
- Around line 11-15: Update the module docstring in src/fromager/versionmap.py
to include a Sphinx ".. versionchanged::" directive documenting the breaking
key-type contract: state that keys are now required to be
packaging.version.Version instances (callers must parse strings) and reference
the mutation method add; include the project version (or placeholder) after "..
versionchanged::" and a short note describing the change and its impact on
callers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5749f994-fd1d-4108-a6fa-233d0b45b23d
📒 Files selected for processing (3)
src/fromager/resolver.pysrc/fromager/versionmap.pytests/test_versionmap.py
🚧 Files skipped from review as they are similar to previous changes (1)
- src/fromager/resolver.py
|
@vshawrh can we squash the commits? |
- Subclass collections.abc.Mapping with Version-only keys (no str coercion) - Use Mapping.items() in VersionMapProvider.find_candidates - Reject non-Version keys with TypeError Co-Authored-By: Claude <claude@anthropic.com> Closes: python-wheel-build#986 Co-authored-by: Cursor <cursoragent@cursor.com>
006ca3f to
9d203c7
Compare
What
VersionMaptopackaging.version.Versionkeys only (no string coercion or parsing inside the map).iter_pairs()to yield(version, value)in descending version order.collections.abc.Mapping(__getitem__,__iter__,__len__); mutations stay onadd().iter_pairs()inVersionMapProvider.find_candidates.Version(...)keys and cover invalid keys plus basicMappingbehavior.Why
Breaking change: code that constructed
VersionMapwith string keys must switch toVersion("…").Closes #986